var liebiao = new Vue({
	el: '#novelList',
	data: {
		current: [],
		rankingList: [],
		localData: {  //使用pass表示该数据为空，所有书对象里都是数组类型，存放最近的三个对象
			latelyType: [{
				id: '',
				title: '',
				icon: '',
				introduce: '',
				go: ""
			}, {
				id: '',
				title: '',
				icon: '',
				introduce: '',
				go: ""
			},{
				id: '',
				title: '',
				icon: '',
				introduce: '',
				go: ""
			},{
				id: '',
				title: '',
				icon: '',
				introduce: '',
				go: ""
			}], //最近浏览的小说类别
			latelyList: [{ // 最近看过的小说
				title: '', // 书名
				href: '',  // 链接
				latelyCatalogue: [{ // 最近看的章节
					chapter: '', // 章节名
					href: ''  // 链接
				},{
					chapter: '', // 章节名
					href: ''  // 链接
				},{
					chapter: '', // 章节名
					href: ''  // 链接
				}]
			},{
				title: '', // 书名
				href: '',  // 链接
				latelyCatalogue: [{ // 最近看的章节
					chapter: '', // 章节名
					href: ''  // 链接
				},{
					chapter: '', // 章节名
					href: ''  // 链接
				},{
					chapter: '', // 章节名
					href: ''  // 链接
				}]
			},{
				title: '', // 书名
				href: '',  // 链接
				latelyCatalogue: [{ // 最近看的章节
					chapter: '', // 章节名
					href: ''  // 链接
				},{
					chapter: '', // 章节名
					href: ''  // 链接
				},{
					chapter: '', // 章节名
					href: ''  // 链接
				}]
			}],
			latelySearch: ['', '', '', '', ''] //最近查询（允许存放5个结果）
		}
	},
	methods: {
		gets: function () {
			var that = this;
			$.ajax({
				type : 'POST',
				url : '/novel/novel_data/',
				dataType : "json",//数据类型为json
				data: {
				    what: 'list',
                    type: $('span.hidden')[0].innerHTML
                },
				success : function(data){
					if(data.result){
						that.current = data.current;
						that.rankingList = data.rankingList
                    }
					$('img#load').addClass('hidden');
				},
				error:function(msg){
					console.log("ajax error msg",msg);
					$('img#load').addClass('hidden');
					$('#promptbtn').click();
				}
			});
        },
        addLatelyCatalogue: function (who, index) {
            var data = who ? this.current : this.rankingList;
            var list = this.localData.latelyList;
            var i = 0;
			for(; i < list.length; i++){
				if(list[i].title === data[index].title){
					break;
				}else if(!list[i].title){
					list[i] = {
						title: data[index].title,
						href: data[index].href,
						latelyCatalogue: [{
							chapter: '',
							href: ''
						},{
							chapter: '',
							href: ''
						},{
							chapter: '',
							href: ''
						}]
					};
					break;
				}
			}
			if(i === list.length){
				list.shift();
				list.push({
					title: data[index].title,
					href: data[index].href,
					latelyCatalogue: [{
						chapter: '',
						href: ''
					},{
						chapter: '',
						href: ''
					},{
						chapter: '',
						href: ''
					}]
				})
			}
			try{
				localStorage.setItem('lately', JSON.stringify(this.localData));
			}catch (err){
				console.log(err);
			}
        }
	},
	computed: {
		page_title: function () {
			switch($('span.hidden')[0].innerHTML){
				case 'coatard':
					return '武侠仙侠';
				case 'urban':
					return '都市言情';
				case 'history':
					return '历史军事';
				case 'webgame':
					return '网游竞技';
				case 'science':
					return '科幻灵异';
				case 'girl':
					return '女频频道';
				// case 'complete':
				// 	return '都市小说';
				default:
					return '玄幻奇幻';
			}
        }
    },
	mounted: function () {
		$('img#load').removeClass('hidden');
		try {
			var data = localStorage.getItem('lately');
			if(data){
				this.localData = JSON.parse(data);
			}else{
				localStorage.setItem('lately', JSON.stringify(this.localData));
			}
		} catch (err) {
			console.log(err);
		}
		this.gets();
	}

});